home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / emacs-complete / fsf / emacs / info / emacs-2 < prev    next >
Encoding:
GNU Info File  |  1994-10-06  |  46.4 KB  |  1,030 lines

  1. This is Info file ../info/emacs, produced by Makeinfo-1.54 from the
  2. input file emacs.texi.
  3.  
  4. 
  5. File: emacs,  Node: Intro,  Next: Glossary,  Prev: Copying,  Up: Top
  6.  
  7. Introduction
  8. ************
  9.  
  10.    You are reading about GNU Emacs, the GNU incarnation of the advanced,
  11. self-documenting, customizable, extensible real-time display editor
  12. Emacs.  (The `G' in `GNU' is not silent.)
  13.  
  14.    We say that Emacs is a "display" editor because normally the text
  15. being edited is visible on the screen and is updated automatically as
  16. you type your commands.  *Note Display: Screen.
  17.  
  18.    We call it a "real-time" editor because the display is updated very
  19. frequently, usually after each character or pair of characters you
  20. type.  This minimizes the amount of information you must keep in your
  21. head as you edit.  *Note Real-time: Basic.
  22.  
  23.    We call Emacs advanced because it provides facilities that go beyond
  24. simple insertion and deletion: controlling subprocesses; automatic
  25. indentation of programs; viewing two or more files at once; and dealing
  26. in terms of characters, words, lines, sentences, paragraphs, and pages,
  27. as well as expressions and comments in several different programming
  28. languages.
  29.  
  30.    "Self-documenting" means that at any time you can type a special
  31. character, `Control-h', to find out what your options are.  You can
  32. also use it to find out what any command does, or to find all the
  33. commands that pertain to a topic.  *Note Help::.
  34.  
  35.    "Customizable" means that you can change the definitions of Emacs
  36. commands in little ways.  For example, if you use a programming
  37. language in which comments start with `<**' and end with `**>', you can
  38. tell the Emacs comment manipulation commands to use those strings
  39. (*note Comments::.).  Another sort of customization is rearrangement of
  40. the command set.  For example, if you prefer the four basic cursor
  41. motion commands (up, down, left and right) on keys in a diamond pattern
  42. on the keyboard, you can rebind the keys that way.  *Note
  43. Customization::.
  44.  
  45.    "Extensible" means that you can go beyond simple customization and
  46. write entirely new commands, programs in the Lisp language to be run by
  47. Emacs's own Lisp interpreter.  Emacs is an "on-line extensible" system,
  48. which means that it is divided into many functions that call each
  49. other, any of which can be redefined in the middle of an editing
  50. session.  Almost any part of Emacs can be replaced without making a
  51. separate copy of all of Emacs.  Most of the editing commands of Emacs
  52. are written in Lisp already; the few exceptions could have been written
  53. in Lisp but are written in C for efficiency.  Although only a programmer
  54. can write an extension, anybody can use it afterward.
  55.  
  56.    When run under the X Window System, Emacs provides its own menus and
  57. convenient bindings to mouse buttons.  But Emacs can provide many of the
  58. benefits of a window system on a text-only terminal.  For instance, you
  59. can look at or edit several files at once, move text between them, and
  60. edit files at the same time as you run shell commands.
  61.  
  62. 
  63. File: emacs,  Node: Screen,  Next: User Input,  Prev: Concept Index,  Up: Top
  64.  
  65. The Organization of the Screen
  66. ******************************
  67.  
  68.    On a text-only terminal, the Emacs display occupies the whole screen.
  69. On the X Window System, Emacs creates its own X windows to use.  We use
  70. the term "frame" to mean an entire text-only screen or an entire X
  71. window used by Emacs.  Emacs uses both kinds of frames in the same way
  72. to display your editing.  Emacs normally starts out with just one frame,
  73. but under X you can create additional frames if you wish.  *Note
  74. Frames::.
  75.  
  76.    When you start Emacs, the entire frame except for the last line is
  77. devoted to the text you are editing.  This area is called "window".
  78. The last line is a special "echo area" or "minibuffer window" where
  79. prompts appear and where you can enter responses.  You can subdivide
  80. the large text window horizontally or vertically into multiple text
  81. windows, each of which can be used for a different file (*note
  82. Windows::.).  In this manual, the word "window" always refers to the
  83. subdivisions of a frame within Emacs.
  84.  
  85.    The window that the cursor is in is the "selected window", in which
  86. editing takes place.  Most Emacs commands implicitly apply to the text
  87. in the selected window (though mouse commands generally operate on
  88. whatever window you click them in, whether selected or not).  The other
  89. windows display text for reference only, unless/until you select them.
  90. If you use multiple frames under the X Window System, then giving the
  91. input focus to a particular frame selects a window in that frame.
  92.  
  93.    Each window's last line is a "mode line" which describes what is
  94. going on in that window.  It appears in inverse video if the terminal
  95. supports that, and contains text that starts like `-----Emacs:
  96. SOMETHING'.  Its purpose is to indicate what buffer is being displayed
  97. above it in the window; what major and minor modes are in use; and
  98. whether the buffer contains unsaved changes.
  99.  
  100. * Menu:
  101.  
  102. * Point::    The place in the text where editing commands operate.
  103. * Echo Area::   Short messages appear at the bottom of the screen.
  104. * Mode Line::    Interpreting the mode line.
  105.  
  106. 
  107. File: emacs,  Node: Point,  Next: Echo Area,  Up: Screen
  108.  
  109. Point
  110. =====
  111.  
  112.    Within Emacs, the terminal's cursor shows the location at which
  113. editing commands will take effect.  This location is called "point".
  114. Many Emacs commands move point through the text, so that you can edit at
  115. different places in it.  You can also place point by clicking mouse
  116. button 1.
  117.  
  118.    While the cursor appears to point AT a character, you should think
  119. of point as BETWEEN two characters; it points BEFORE the character that
  120. appears under the cursor.  For example, if your text looks like `frob'
  121. with the cursor over the `b', then point is between the `o' and the
  122. `b'.  If you insert the character `!' at that position, the result is
  123. `fro!b', with point between the `!' and the `b'.  Thus, the cursor
  124. remains over the `b', as before.
  125.  
  126.    Sometimes people speak of "the cursor" when they mean "point", or
  127. speak of commands that move point as "cursor motion" commands.
  128.  
  129.    Terminals have only one cursor, and when output is in progress it
  130. must appear where the typing is being done.  This does not mean that
  131. point is moving.  It is only that Emacs has no way to show you the
  132. location of point except when the terminal is idle.
  133.  
  134.    If you are editing several files in Emacs, each in its own buffer,
  135. each buffer has its own point location.  A buffer that is not currently
  136. displayed remembers where point is in case you display it again later.
  137.  
  138.    When there are multiple windows in a frame, each window has its own
  139. point location.  The cursor shows the location of point in the selected
  140. window.  This also is how you can tell which window is selected.  If the
  141. same buffer appears in more than one window, each window has its own
  142. position for point in that buffer.
  143.  
  144.    When there are multiple frames, each frame can display one cursor.
  145. The cursor in the selected frame is solid; the cursor in other frames is
  146. a hollow box, and appears in the window that would be selected if you
  147. give the input focus to that frame.
  148.  
  149.    The term `point' comes from the character `.', which was the command
  150. in TECO (the language in which the original Emacs was written) for
  151. accessing the value now called `point'.
  152.  
  153. 
  154. File: emacs,  Node: Echo Area,  Next: Mode Line,  Prev: Point,  Up: Screen
  155.  
  156. The Echo Area
  157. =============
  158.  
  159.    The line at the bottom of the frame (below the mode line) is the
  160. "echo area".  It is used to display small amounts of text for several
  161. purposes.
  162.  
  163.    "Echoing" means displaying the characters that you type.  Outside
  164. Emacs, the operating system normally echoes all your input.  Emacs
  165. handles echoing differently.
  166.  
  167.    Single-character commands do not echo in Emacs, and multi-character
  168. commands echo only if you pause while typing them.  As soon as you pause
  169. for more than a second in the middle of a command, Emacs echoes all the
  170. characters of the command so far.  This is to "prompt" you for the rest
  171. of the command.  Once echoing has started, the rest of the command
  172. echoes immediately as you type it.  This behavior is designed to give
  173. confident users fast response, while giving hesitant users maximum
  174. feedback.  You can change this behavior by setting a variable (*note
  175. Display Vars::.).
  176.  
  177.    If a command cannot be executed, it may print an "error message" in
  178. the echo area.  Error messages are accompanied by a beep or by flashing
  179. the screen.  Also, any input you have typed ahead is thrown away when
  180. an error happens.
  181.  
  182.    Some commands print informative messages in the echo area.  These
  183. messages look much like error messages, but they are not announced with
  184. a beep and do not throw away input.  Sometimes the message tells you
  185. what the command has done, when this is not obvious from looking at the
  186. text being edited.  Sometimes the sole purpose of a command is to print
  187. a message giving you specific information--for example, `C-x =' prints
  188. a message describing the character position of point in the text and
  189. its current column in the window.  Commands that take a long time often
  190. display messages ending in `...' while they are working, and add `done'
  191. at the end when they are finished.
  192.  
  193.    The echo area is also used to display the "minibuffer", a window that
  194. is used for reading arguments to commands, such as the name of a file
  195. to be edited.  When the minibuffer is in use, the echo area begins with
  196. a prompt string that usually ends with a colon; also, the cursor
  197. appears in that line because it is the selected window.  You can always
  198. get out of the minibuffer by typing `C-g'.  *Note Minibuffer::.
  199.  
  200. 
  201. File: emacs,  Node: Mode Line,  Prev: Echo Area,  Up: Screen
  202.  
  203. The Mode Line
  204. =============
  205.  
  206.    Each text window's last line is a "mode line" which describes what
  207. is going on in that window.  When there is only one text window, the
  208. mode line appears right above the echo area.  The mode line is in
  209. inverse video if the terminal supports that, it starts and ends with
  210. dashes, and it contains text like `Emacs: SOMETHING'.
  211.  
  212.    A few special editing modes, such as Dired and Rmail, display
  213. something else in place of `Emacs: SOMETHING'.  The rest of the mode
  214. line still has the usual meaning.
  215.  
  216.    Normally, the mode line looks like this:
  217.  
  218.      --CH-Emacs: BUF      (MAJOR MINOR)----POS------
  219.  
  220. This gives information about the buffer being displayed in the window:
  221. the buffer's name, what major and minor modes are in use, whether the
  222. buffer's text has been changed, and how far down the buffer you are
  223. currently looking.
  224.  
  225.    CH contains two stars `**' if the text in the buffer has been edited
  226. (the buffer is "modified"), or `--' if the buffer has not been edited.
  227. For a read-only buffer, it is `%*' if the buffer is modified, and `%%'
  228. otherwise.
  229.  
  230.    BUF is the name of the window's "buffer".  In most cases this is the
  231. same as the name of a file you are editing.  *Note Buffers::.
  232.  
  233.    The buffer displayed in the selected window (the window that the
  234. cursor is in) is also Emacs's selected buffer, the one that editing
  235. takes place in.  When we speak of what some command does to "the
  236. buffer", we are talking about the currently selected buffer.
  237.  
  238.    POS tells you whether there is additional text above the top of the
  239. window, or below the bottom.  If your buffer is small and it is all
  240. visible in the window, POS is `All'.  Otherwise, it is `Top' if you are
  241. looking at the beginning of the buffer, `Bot' if you are looking at the
  242. end of the buffer, or `NN%', where NN is the percentage of the buffer
  243. above the top of the window.
  244.  
  245.    MAJOR is the name of the "major mode" in effect in the buffer.  At
  246. any time, each buffer is in one and only one of the possible major
  247. modes.  The major modes available include Fundamental mode (the least
  248. specialized), Text mode, Lisp mode, C mode, Texinfo mode, and many
  249. others.  *Note Major Modes::, for details of how the modes differ and
  250. how to select one.
  251.  
  252.    Some major modes display additional information after the major mode
  253. name.  For example, Rmail buffers display the current message number and
  254. the total number of messages.  Compilation buffers and Shell buffers
  255. display the status of the subprocess.
  256.  
  257.    MINOR is a list of some of the "minor modes" that are turned on at
  258. the moment in the window's chosen buffer.  For example, `Fill' means
  259. that Auto Fill mode is on.  `Abbrev' means that Word Abbrev mode is on.
  260. `Ovwrt' means that Overwrite mode is on.  *Note Minor Modes::, for
  261. more information.  `Narrow' means that the buffer being displayed has
  262. editing restricted to only a portion of its text.  This is not really a
  263. minor mode, but is like one.  *Note Narrowing::.  `Def' means that a
  264. keyboard macro is being defined.  *Note Keyboard Macros::.
  265.  
  266.    In addition, if Emacs is currently inside a recursive editing level,
  267. square brackets (`[...]') appear around the parentheses that surround
  268. the modes.  If Emacs is in one recursive editing level within another,
  269. double square brackets appear, and so on.  Since recursive editing
  270. levels affect Emacs globally, not just one buffer, the square brackets
  271. appear in every window's mode line or not in any of them.  *Note
  272. Recursive Edit::.
  273.  
  274.    *Note Optional Mode Line::, for features that add other handy
  275. information to the mode line, such as the current line number of point,
  276. the current time, and whether new mail for you has arrived.
  277.  
  278. 
  279. File: emacs,  Node: User Input,  Next: Keys,  Prev: Screen,  Up: Top
  280.  
  281. Kinds of User Input
  282. ===================
  283.  
  284.    GNU Emacs uses an extension of the ASCII character set for keyboard
  285. input; it also accepts non-character input events including function
  286. keys and mouse button actions.
  287.  
  288.    ASCII consists of 128 character codes.  Some of these codes are
  289. assigned graphic symbols such as `a' and `='; the rest are control
  290. characters, such as `Control-a' (usually written `C-a' for short).
  291. `C-a' gets its name from the fact that you type it by holding down the
  292. CTRL key and then pressing `a'.
  293.  
  294.    Some control characters have special names, and special keys you can
  295. type them with: for example, RET, TAB, LFD, DEL and ESC.  The space
  296. character is usually referred to below as SPC, even though strictly
  297. speaking it is a graphic character whose graphic happens to be blank.
  298.  
  299.    On ASCII terminals, there are only 32 possible control characters.
  300. These are the control variants of letters and `@[]\^_'.  In addition,
  301. the shift key is meaningless with control characters: `C-a' and `C-A'
  302. are the same character, and Emacs cannot distinguish them.
  303.  
  304.    But the Emacs character set has room for control variants of all
  305. characters, and for distinguishing between `C-a' and `C-A'.  X Windows
  306. makes it possible to enter all these characters.  For example, `C--'
  307. (that's Control-Minus) and `C-5' are meaningful Emacs commands under X.
  308.  
  309.    Another Emacs character set extension is that characters have
  310. additional modifier bits.  Only one modifier bit is commonly used; it is
  311. called Meta.  Every character has a Meta variant; examples include
  312. `Meta-a' (normally written `M-a', for short), `M-A' (not the same
  313. character as `M-a', but those two characters normally have the same
  314. meaning in Emacs), `M-RET', and `M-C-a'.  For reasons of tradition, we
  315. usually write `C-M-a' rather than `M-C-a'; logically speaking, the
  316. order in which the modifier keys CTRL and META are mentioned does not
  317. matter.
  318.  
  319.    Some terminals have a META key, and allow you to type Meta
  320. characters by holding this key down.  Thus, `Meta-a' is typed by
  321. holding down META and pressing `a'.  The META key works much like the
  322. SHIFT key.  Such a key is not always labeled META, however, as this
  323. function is often a special option for a key with some other primary
  324. purpose.
  325.  
  326.    If there is no META key, you can still type Meta characters using
  327. two-character sequences starting with ESC.  Thus, to enter `M-a', you
  328. could type `ESC a'.  To enter `C-M-a', you would type `ESC C-a'.  ESC
  329. is allowed on terminals with Meta keys, too, in case you have formed a
  330. habit of using it.
  331.  
  332.    X Windows provides several other modifier keys that can be applied to
  333. any input character.  These are called SUPER, HYPER and ALT.  We write
  334. `s-', `H-' and `A-' to say that a character uses these modifiers.
  335. Thus, `s-H-C-x' is short for `Super-Hyper-Control-x'.  Not all X
  336. terminals actually provide keys for these modifier flags, and the
  337. standard key bindings of Emacs do not include such characters.  But you
  338. can assign them meanings of your own by customizing Emacs.
  339.  
  340.    Keyboard input includes keyboard keys that are not characters at all:
  341. for example function keys and arrow keys.  Mouse buttons are also
  342. outside the gamut of characters.  You can modify these events with the
  343. modifier keys CONTROL, META, SUPER, HYPER and ALT like keyboard
  344. characters.  But these inputs do not have numeric character codes.
  345. Instead, Emacs represents them by their names (actually, Lisp objects
  346. called "symbols").
  347.  
  348.    Input characters and non-character inputs are collectively called
  349. "input events".  *Note Input Events: (elisp)Input Events, for more
  350. information.  If you are not doing Lisp programming, but simply want to
  351. redefine the meaning of some characters or non-character events, see
  352. *Note Customization::.
  353.  
  354.    ASCII terminals cannot really send anything to the computer except
  355. ASCII characters.  These terminals use a sequence of characters to
  356. represent each function key.  But that is invisible to the Emacs user,
  357. because the keyboard input routines recognize these special sequences
  358. and converts them to names before any other part of Emacs gets to see
  359. them.
  360.  
  361. 
  362. File: emacs,  Node: Keys,  Next: Commands,  Prev: User Input,  Up: Top
  363.  
  364. Keys
  365. ====
  366.  
  367.    A "key sequence" ("key", for short) is a sequence of input events
  368. that are meaningful as a unit--as "a single command." Some Emacs
  369. command sequences are just one character or one event; for example,
  370. just `C-f' is enough to move forward one character.  But Emacs also has
  371. commands that take two or more events to invoke.
  372.  
  373.    If a sequence of events is enough to invoke a command, it is a
  374. "complete key".  Examples of complete keys include `C-a', `X', RET,
  375. NEXT (a function key), DOWN (an arrow key), `C-x C-f' and `C-x 4 C-f'.
  376. If it isn't long enough to be complete, we call it a "prefix key".  The
  377. above examples show that `C-x' and `C-x 4' are prefix keys.  Every key
  378. sequence is either a complete key or a prefix key.
  379.  
  380.    Most single characters constitute complete keys in the standard Emacs
  381. command bindings.  A few of them are prefix keys.  A prefix key combines
  382. with the following input event to make a longer key sequence, which may
  383. itself be complete or a prefix.  For example, `C-x' is a prefix key, so
  384. `C-x' and the next input event combine to make a two-character key
  385. sequence.  Most of these key sequences are complete keys, including
  386. `C-x C-f' and `C-x b'.  A few, such as `C-x 4' and `C-x r', are
  387. themselves prefix keys that lead to three-character key sequences.
  388. There's no limit to the length of a key sequence, but in practice
  389. people rarely use sequences longer than four events.
  390.  
  391.    By contrast, you can't add more events onto a complete key.  For
  392. example, the two-character sequence `C-f C-k' is not a key, because the
  393. `C-f' is a complete key in itself.  It's impossible to give `C-f C-k'
  394. an independent meaning as a command.  `C-f C-k' is two key sequences,
  395. not one.
  396.  
  397.    All told, the prefix keys in Emacs are `C-c', `C-h', `C-x', `C-x
  398. C-a', `C-x n', `C-x r', `C-x v', `C-x 4', `C-x 5', `C-x 6', and ESC.
  399. But this is not cast in concrete; it is just a matter of Emacs's
  400. standard key bindings.  If you customize Emacs, you can make new prefix
  401. keys, or eliminate these.  *Note Key Bindings::.
  402.  
  403.    If you do make or eliminate prefix keys, that changes the set of
  404. possible key sequences.  For example, if you redefine `C-f' as a
  405. prefix, `C-f C-k' automatically becomes a key (complete, unless you
  406. define it too as a prefix).  Conversely, if you remove the prefix
  407. definition of `C-x 4', then `C-x 4 f' (or `C-x 4 ANYTHING') is no
  408. longer a key.
  409.  
  410.    Typing the help character (`C-h') after a prefix character usually
  411. displays a list of the commands starting with that prefix.  There are a
  412. few prefix characters for which this doesn't work--for historical
  413. reasons, they have other meanings for `C-h' which are not easy to
  414. change.
  415.  
  416. 
  417. File: emacs,  Node: Commands,  Next: Text Characters,  Prev: Keys,  Up: Top
  418.  
  419. Keys and Commands
  420. =================
  421.  
  422.    This manual is full of passages that tell you what particular keys
  423. do.  But Emacs does not assign meanings to keys directly.  Instead,
  424. Emacs assigns meanings to named "commands", and then gives keys their
  425. meanings by "binding" them to commands.
  426.  
  427.    Every command has a name chosen by a programmer.  The name is usually
  428. made of a few English words separated by dashes; for example,
  429. `next-line' or `forward-word'.  A command also has a "function
  430. definition" which is a Lisp program; this is what makes the command do
  431. what it does.  In Emacs Lisp, a command is actually a special kind of
  432. Lisp function; one which specifies how to read arguments for it and
  433. call it interactively.  For more information on commands and functions,
  434. see *Note What Is a Function: (elisp)What Is a Function.  (The
  435. definition we use in this manual is simplified slightly.)
  436.  
  437.    The bindings between keys and commands are recorded in various tables
  438. called "keymaps".  *Note Keymaps::.
  439.  
  440.    When we say that "`C-n' moves down vertically one line" we are
  441. glossing over a distinction that is irrelevant in ordinary use but is
  442. vital in understanding how to customize Emacs.  It is the command
  443. `next-line' that is programmed to move down vertically.  `C-n' has this
  444. effect *because* it is bound to that command.  If you rebind `C-n' to
  445. the command `forward-word' then `C-n' will move forward by words
  446. instead.  Rebinding keys is a common method of customization.
  447.  
  448.    In the rest of this manual, we usually ignore this subtlety to keep
  449. things simple.  To give the information needed for customization, we
  450. state the name of the command which really does the work in parentheses
  451. after mentioning the key that runs it.  For example, we will say that
  452. "The command `C-n' (`next-line') moves point vertically down," meaning
  453. that `next-line' is a command that moves vertically down and `C-n' is a
  454. key that is standardly bound to it.
  455.  
  456.    While we are on the subject of information for customization only,
  457. it's a good time to tell you about "variables".  Often the description
  458. of a command will say, "To change this, set the variable `mumble-foo'."
  459. A variable is a name used to remember a value.  Most of the variables
  460. documented in this manual exist just to facilitate customization: some
  461. command or other part of Emacs examines the variable and behaves
  462. differently according to the value that you set.  Until you are
  463. interested in customizing, you can ignore the information about
  464. variables.  When you are ready to be interested, read the basic
  465. information on variables, and then the information on individual
  466. variables will make sense.  *Note Variables::.
  467.  
  468. 
  469. File: emacs,  Node: Text Characters,  Next: Entering Emacs,  Prev: Commands,  Up: Top
  470.  
  471. Character Set for Text
  472. ======================
  473.  
  474.    Emacs buffers use an 8-bit character set, because bytes have 8 bits.
  475. ASCII graphic characters in Emacs buffers are displayed with their
  476. graphics.  The newline character (which has the same character code as
  477. LFD) is displayed by starting a new line.  The tab character is
  478. displayed by moving to the next tab stop column (normally every 8
  479. columns).  Other control characters are displayed as a caret (`^')
  480. followed by the non-control version of the character; thus, `C-a' is
  481. displayed as `^A'.  Non-ASCII characters 128 and up are displayed with
  482. octal escape sequences; thus, character code 243 (octal) is displayed
  483. as `\243'.
  484.  
  485.    You can customize the display of these character codes (or ASCII
  486. characters) by creating a "display table".  *Note Display Tables:
  487. (elisp)Display Tables.  This is useful for editing files that use 8-bit
  488. European character sets.  *Note European Display::.
  489.  
  490. 
  491. File: emacs,  Node: Entering Emacs,  Next: Exiting,  Prev: Text Characters,  Up: Top
  492.  
  493. Entering and Exiting Emacs
  494. **************************
  495.  
  496.    The usual way to invoke Emacs is with the shell command `emacs'.
  497. Emacs clears the screen and then displays an initial help message and
  498. copyright notice.  Some operating systems discard all type-ahead when
  499. Emacs starts up; they give Emacs no way to prevent this.  Therefore, it
  500. is advisable to wait until Emacs clears the screen before typing your
  501. first editing command.
  502.  
  503.    If you run Emacs from a shell window under the X Window System, run
  504. it in the background with `emacs&'.  This way, Emacs does not tie up
  505. the shell window, so you can use that to run other shell commands while
  506. Emacs operates its own X windows.  You can begin typing Emacs commands
  507. as soon as you direct your keyboard input to the Emacs frame.
  508.  
  509.    When Emacs starts up, it makes a buffer named `*scratch*'.  That's
  510. the buffer you start out in.  The `*scratch*' buffer uses Lisp
  511. Interaction mode; you can use it to type Lisp expressions and evaluate
  512. them, or you can ignore that capability and simply doodle.  (You can
  513. specify a different major mode for this buffer by setting the variable
  514. `initial-major-mode' in your init file.  *Note Init File::.)
  515.  
  516.    It is possible to specify files to be visited, Lisp files to be
  517. loaded, and functions to be called, by giving Emacs arguments in the
  518. shell command line.  *Note Command Arguments::.  But we don't recommend
  519. doing this.  The feature exists mainly for compatibility with other
  520. editors.
  521.  
  522.    Many other editors are designed to be started afresh each time you
  523. want to edit.  You edit one file and then exit the editor.  The next
  524. time you want to edit either another file or the same one, you must run
  525. the editor again.  With these editors, it makes sense to use a command
  526. line argument to say which file to edit.
  527.  
  528.    But starting a new Emacs each time you want to edit a different file
  529. does not make sense.  For one thing, this would be annoyingly slow.  For
  530. another, this would fail to take advantage of Emacs's ability to visit
  531. more than one file in a single editing session.  And it would lose the
  532. other accumulated context, such as registers, undo history, and the mark
  533. ring.
  534.  
  535.    The recommended way to use GNU Emacs is to start it only once, just
  536. after you log in, and do all your editing in the same Emacs session.
  537. Each time you want to edit a different file, you visit it with the
  538. existing Emacs, which eventually comes to have many files in it ready
  539. for editing.  Usually you do not kill the Emacs until you are about to
  540. log out.  *Note Files::, for more information on visiting more than one
  541. file.
  542.  
  543. 
  544. File: emacs,  Node: Exiting,  Next: Basic,  Prev: Entering Emacs,  Up: Top
  545.  
  546. Exiting Emacs
  547. =============
  548.  
  549.    There are two commands for exiting Emacs because there are two kinds
  550. of exiting: "suspending" Emacs and "killing" Emacs.
  551.  
  552.    "Suspending" means stopping Emacs temporarily and returning control
  553. to its parent process (usually a shell), allowing you to resume editing
  554. later in the same Emacs job, with the same buffers, same kill ring,
  555. same undo history, and so on.  This is the usual way to exit.
  556.  
  557.    "Killing" Emacs means destroying the Emacs job.  You can run Emacs
  558. again later, but you will get a fresh Emacs; there is no way to resume
  559. the same editing session after it has been killed.
  560.  
  561. `C-z'
  562.      Suspend Emacs (`suspend-emacs') or iconify a frame
  563.      (`iconify-or-deiconify-frame').
  564.  
  565. `C-x C-c'
  566.      Kill Emacs (`save-buffers-kill-emacs').
  567.  
  568.    To suspend Emacs, type `C-z' (`suspend-emacs').  This takes you back
  569. to the shell from which you invoked Emacs.  You can resume Emacs with
  570. the shell command `%emacs' in most common shells.
  571.  
  572.    On systems that do not support suspending programs, `C-z' starts an
  573. inferior shell that communicates directly with the terminal.  Emacs
  574. waits until you exit the subshell.  (The way to do that is probably
  575. with `C-d' or `exit', but it depends on which shell you use.)  The only
  576. way on these systems to get back to the shell from which Emacs was run
  577. (to log out, for example) is to kill Emacs.
  578.  
  579.    Suspending also fails if you run Emacs under a shell that doesn't
  580. support suspending programs, even if the system itself does support it.
  581. In such a case, you can set the variable `cannot-suspend' to a
  582. non-`nil' value to force `C-z' to start an inferior shell.  (One might
  583. also describe Emacs's parent shell as "inferior" for failing to support
  584. job control properly, but that is a matter of taste.)
  585.  
  586.    When Emacs communicates directly with an X server and creates its own
  587. dedicated X windows, `C-z' has a different meaning.  Suspending an
  588. applications that uses its own X windows is not meaningful or useful.
  589. Instead, `C-z' runs the command `iconify-or-deiconify-frame', which
  590. temporarily closes up the selected Emacs frame.  The way to get back to
  591. a shell window is with the window manager.
  592.  
  593.    To kill Emacs, type `C-x C-c' (`save-buffers-kill-emacs').  A
  594. two-character key is used for this to make it harder to type.  This
  595. command first offers to save any modified file-visiting buffers.  If you
  596. do not save them all, it asks for reconfirmation with `yes' before
  597. killing Emacs, since any changes not saved will be lost forever.  Also,
  598. if any subprocesses are still running, `C-x C-c' asks for confirmation
  599. about them, since killing Emacs will kill the subprocesses immediately.
  600.  
  601.    There is no way to restart an Emacs session once you have killed it.
  602. You can, however, arrange for Emacs to record certain session
  603. information, such as which files are visited, when you kill it, so that
  604. the next time you restart Emacs it will try to visit the same files and
  605. so on.  *Note Saving Emacs Sessions::.
  606.  
  607.    The operating system usually listens for certain special characters
  608. whose meaning is to kill or suspend the program you are running.  This
  609. operating system feature is turned off while you are in Emacs.  The
  610. meanings of `C-z' and `C-x C-c' as keys in Emacs were inspired by the
  611. use of `C-z' and `C-c' on several operating systems as the characters
  612. for stopping or killing a program, but that is their only relationship
  613. with the operating system.  You can customize these keys to run any
  614. commands of your choice (*note Keymaps::.).
  615.  
  616. 
  617. File: emacs,  Node: Basic,  Next: Minibuffer,  Prev: Exiting,  Up: Top
  618.  
  619. Basic Editing Commands
  620. **********************
  621.  
  622.    We now give the basics of how to enter text, make corrections, and
  623. save the text in a file.  If this material is new to you, you might
  624. learn it more easily by running the Emacs learn-by-doing tutorial.  To
  625. use the tutorial, run Emacs and type `Control-h t'
  626. (`help-with-tutorial').
  627.  
  628.    To clear the screen and redisplay, type `C-l' (`recenter').
  629.  
  630. * Menu:
  631.  
  632. * Inserting Text::     Inserting text by simply typing it.
  633. * Moving Point::       How to move the cursor to the place where you want to
  634.                  change something.
  635. * Erasing::           Deleting and killing text.
  636. * Undo::               Undoing previous changes.
  637. * Files: Basic Files.  Visiting, creating, and saving files.
  638. * Help: Basic Help.    Asking what a character does.
  639. * Blank Lines::        Commands to make or delete blank lines.
  640. * Continuation Lines:: Lines too wide for the screen.
  641. * Position Info::      What page, line, row, or column is point on?
  642. * Arguments::           Numeric arguments for repeating a command.
  643.  
  644. 
  645. File: emacs,  Node: Inserting Text,  Next: Moving Point,  Up: Basic
  646.  
  647. Inserting Text
  648. ==============
  649.  
  650.    To insert printing characters into the text you are editing, just
  651. type them.  This inserts the characters you type into the buffer at the
  652. cursor (that is, at "point"; *note Point::.).  The cursor moves
  653. forward, and any text after the cursor moves forward too.  If the text
  654. in the buffer is `FOOBAR', with the cursor before the `B', then if you
  655. type `XX', you get `FOOXXBAR', with the cursor still before the `B'.
  656.  
  657.    To "delete" text you have just inserted, use DEL.  DEL deletes the
  658. character *before* the cursor (not the one that the cursor is on top of
  659. or under; that is the character AFTER the cursor).  The cursor and all
  660. characters after it move backwards.  Therefore, if you type a printing
  661. character and then type DEL, they cancel out.
  662.  
  663.    To end a line and start typing a new one, type RET.  This inserts a
  664. newline character in the buffer.  If point is in the middle of a line,
  665. RET splits the line.  Typing DEL when the cursor is at the beginning of
  666. a line deletes the preceding newline, thus joining the line with the
  667. preceding line.
  668.  
  669.    Emacs can split lines automatically when they become too long, if you
  670. turn on a special minor mode called "Auto Fill" mode.  *Note Filling::,
  671. for how to use Auto Fill mode.
  672.  
  673.    If you prefer to have text characters replace (overwrite) existing
  674. text rather than shove it to the right, you can enable Overwrite mode,
  675. a minor mode.  *Note Minor Modes::.
  676.  
  677.    Direct insertion works for printing characters and SPC, but other
  678. characters act as editing commands and do not insert themselves.  If you
  679. need to insert a control character or a character whose code is above
  680. 200 octal, you must "quote" it by typing the character `Control-q'
  681. (`quoted-insert') first.  (This character's name is normally written
  682. `C-q' for short.)  There are two ways to use `C-q':
  683.  
  684.    * `C-q' followed by any non-graphic character (even `C-g') inserts
  685.      that character.
  686.  
  687.    * `C-q' followed by three octal digits inserts the character with
  688.      the specified character code.
  689.  
  690. A numeric argument to `C-q' specifies how many copies of the quoted
  691. character should be inserted (*note Arguments::.).
  692.  
  693.    Customization information: DEL in most modes runs the command
  694. `delete-backward-char'; RET runs the command `newline', and
  695. self-inserting printing characters run the command `self-insert', which
  696. inserts whatever character was typed to invoke it.  Some major modes
  697. rebind DEL to other commands.
  698.  
  699. 
  700. File: emacs,  Node: Moving Point,  Next: Erasing,  Prev: Inserting Text,  Up: Basic
  701.  
  702. Changing the Location of Point
  703. ==============================
  704.  
  705.    To do more than insert characters, you have to know how to move point
  706. (*note Point::.).  The simplest way to do this is with arrow keys, or by
  707. clicking the left mouse button where you want to move to.
  708.  
  709.    There are also control and meta characters for cursor motion.  Some
  710. are equivalent to the arrow keys (these date back to the days before
  711. terminals had arrow keys, and are usable on terminals which don't have
  712. them).  Others do more sophisticated things.
  713.  
  714. `C-a'
  715.      Move to the beginning of the line (`beginning-of-line').
  716.  
  717. `C-e'
  718.      Move to the end of the line (`end-of-line').
  719.  
  720. `C-f'
  721.      Move forward one character (`forward-char').
  722.  
  723. `C-b'
  724.      Move backward one character (`backward-char').
  725.  
  726. `M-f'
  727.      Move forward one word (`forward-word').
  728.  
  729. `M-b'
  730.      Move backward one word (`backward-word').
  731.  
  732. `C-n'
  733.      Move down one line, vertically (`next-line').  This command
  734.      attempts to keep the horizontal position unchanged, so if you
  735.      start in the middle of one line, you end in the middle of the
  736.      next.  When on the last line of text, `C-n' creates a new line and
  737.      moves onto it.
  738.  
  739. `C-p'
  740.      Move up one line, vertically (`previous-line').
  741.  
  742. `M-r'
  743.      Move point to left margin, vertically centered in the window
  744.      (`move-to-window-line').  Text does not move on the screen.
  745.  
  746.      A numeric argument says which screen line to place point on.  It
  747.      counts screen lines down from the top of the window (zero for the
  748.      top line).  A negative argument counts lines from the bottom (-1
  749.      for the bottom line).
  750.  
  751. `M-<'
  752.      Move to the top of the buffer (`beginning-of-buffer').  With
  753.      numeric argument N, move to N/10 of the way from the top.  *Note
  754.      Arguments::, for more information on numeric arguments.
  755.  
  756. `M->'
  757.      Move to the end of the buffer (`end-of-buffer').
  758.  
  759. `M-x goto-char'
  760.      Read a number N and move point to character number N.  Position 1
  761.      is the beginning of the buffer.
  762.  
  763. `M-x goto-line'
  764.      Read a number N and move point to line number N.  Line 1 is the
  765.      beginning of the buffer.
  766.  
  767. `C-x C-n'
  768.      Use the current column of point as the "semipermanent goal column"
  769.      for `C-n' and `C-p' (`set-goal-column').  Henceforth, those
  770.      commands always move to this column in each line moved into, or as
  771.      close as possible given the contents of the line.  This goal
  772.      column remains in effect until canceled.
  773.  
  774. `C-u C-x C-n'
  775.      Cancel the goal column.  Henceforth, `C-n' and `C-p' once again
  776.      try to stick to a fixed horizontal position, as usual.
  777.  
  778.    If you set the variable `track-eol' to a non-`nil' value, then `C-n'
  779. and `C-p' when at the end of the starting line move to the end of
  780. another line.  Normally, `track-eol' is `nil'.  *Note Variables::, for
  781. how to set variables such as `track-eol'.
  782.  
  783.    Normally, `C-n' on the last line of a buffer appends a newline to
  784. it.  If the variable `next-line-add-newlines' is `nil', then `C-n' gets
  785. an error instead (like `C-p' on the first line).
  786.  
  787. 
  788. File: emacs,  Node: Erasing,  Next: Undo,  Prev: Moving Point,  Up: Basic
  789.  
  790. Erasing Text
  791. ============
  792.  
  793. `DEL'
  794.      Delete the character before point (`delete-backward-char').
  795.  
  796. `C-d'
  797.      Delete the character after point (`delete-char').
  798.  
  799. `C-k'
  800.      Kill to the end of the line (`kill-line').
  801.  
  802. `M-d'
  803.      Kill forward to the end of the next word (`kill-word').
  804.  
  805. `M-DEL'
  806.      Kill back to the beginning of the previous word
  807.      (`backward-kill-word').
  808.  
  809.    You already know about the DEL key which deletes the character
  810. before point (that is, before the cursor).  Another key, `Control-d'
  811. (`C-d' for short), deletes the character after point (that is, the
  812. character that the cursor is on).  This shifts the rest of the text on
  813. the line to the left.  If you type `C-d' at the end of a line, it joins
  814. together that line and the next line.
  815.  
  816.    To erase a larger amount of text, use the `C-k' key, which kills a
  817. line at a time.  If you type `C-k' at the beginning or middle of a
  818. line, it kills all the text up to the end of the line.  If you type
  819. `C-k' at the end of a line, it joins that line and the next line.
  820.  
  821.    *Note Killing::, for more flexible ways of killing text.
  822.  
  823. 
  824. File: emacs,  Node: Undo,  Next: Basic Files,  Prev: Erasing,  Up: Basic
  825.  
  826. Undoing Changes
  827. ===============
  828.  
  829.    You can undo all the recent changes in the buffer text, up to a
  830. certain point.  Each buffer records changes individually, and the undo
  831. command always applies to the current buffer.  Usually each editing
  832. command makes a separate entry in the undo records, but some commands
  833. such as `query-replace' make many entries, and very simple commands
  834. such as self-inserting characters are often grouped to make undoing less
  835. tedious.
  836.  
  837. `C-x u'
  838.      Undo one batch of changes--usually, one command worth (`undo').
  839.  
  840. `C-_'
  841.      The same.
  842.  
  843.    The command `C-x u' or `C-_' is how you undo.  The first time you
  844. give this command, it undoes the last change.  Point moves back to
  845. where it was before the command that made the change.
  846.  
  847.    Consecutive repetitions of `C-_' or `C-x u' undo earlier and earlier
  848. changes, back to the limit of the undo information available.  If all
  849. recorded changes have already been undone, the undo command prints an
  850. error message and does nothing.
  851.  
  852.    Any command other than an undo command breaks the sequence of undo
  853. commands.  Starting from that moment, the previous undo commands become
  854. ordinary changes that you can undo.  Thus, to redo changes you have
  855. undone, type `C-f' or any other command that will harmlessly break the
  856. sequence of undoing, then type more undo commands.
  857.  
  858.    If you notice that a buffer has been modified accidentally, the
  859. easiest way to recover is to type `C-_' repeatedly until the stars
  860. disappear from the front of the mode line.  At this time, all the
  861. modifications you made have been canceled.  Whenever an undo command
  862. makes the stars disappear from the mode line, it means that the buffer
  863. contents are the same as they were when the file was last read in or
  864. saved.
  865.  
  866.    If you do not remember whether you changed the buffer deliberately,
  867. type `C-_' once.  When you see the last change you made undone, you
  868. will see whether it was an intentional change.  If it was an accident,
  869. leave it undone.  If it was deliberate, redo the change as described
  870. above.
  871.  
  872.    Not all buffers record undo information.  Buffers whose names start
  873. with spaces don't; these buffers are used internally by Emacs and its
  874. extensions to hold text that users don't normally look at or edit.
  875.  
  876.    You cannot undo mere cursor motion; only changes in the buffer
  877. contents save undo information.  However, some cursor motion commands
  878. set the mark, so if you use these commands from time to time, you can
  879. move back to the neighborhoods you have moved through by popping the
  880. mark ring (*note Mark Ring::.).
  881.  
  882.    When the undo information for a buffer becomes too large, Emacs
  883. discards the oldest undo information from time to time (during garbage
  884. collection).  You can specify how much undo information to keep by
  885. setting two variables: `undo-limit' and `undo-strong-limit'.  Their
  886. values are expressed in units of bytes of space.
  887.  
  888.    The variable `undo-limit' sets a soft limit: Emacs keeps undo data
  889. for enough commands to reach this size, and perhaps exceed it, but does
  890. not keep data for any earlier commands beyond that.  Its default value
  891. is 20000.  The variable `undo-strong-limit' sets a stricter limit: the
  892. command which pushes the size past this amount is itself forgotten.
  893. Its default value is 30000.
  894.  
  895.    Regardless of the values of those variables, the most recent change
  896. is never discarded, so there is no danger that garbage collection
  897. occurring right after an unintentional large change might prevent you
  898. from undoing it.
  899.  
  900.    The reason the `undo' command has two keys, `C-x u' and `C-_', set
  901. up to run it is that it is worthy of a single-character key, but on
  902. some keyboards it is not obvious how to type `C-_'.  `C-x u' is an
  903. alternative you can type straightforwardly on any terminal.
  904.  
  905. 
  906. File: emacs,  Node: Basic Files,  Next: Basic Help,  Prev: Undo,  Up: Basic
  907.  
  908. Files
  909. =====
  910.  
  911.    The commands described above are sufficient for creating and altering
  912. text in an Emacs buffer; the more advanced Emacs commands just make
  913. things easier.  But to keep any text permanently you must put it in a
  914. "file".  Files are named units of text which are stored by the
  915. operating system for you to retrieve later by name.  To look at or use
  916. the contents of a file in any way, including editing the file with
  917. Emacs, you must specify the file name.
  918.  
  919.    Consider a file named `/usr/rms/foo.c'.  In Emacs, to begin editing
  920. this file, type
  921.  
  922.      C-x C-f /usr/rms/foo.c RET
  923.  
  924. Here the file name is given as an "argument" to the command `C-x C-f'
  925. (`find-file').  That command uses the "minibuffer" to read the
  926. argument, and you type RET to terminate the argument (*note
  927. Minibuffer::.).
  928.  
  929.    Emacs obeys the command by "visiting" the file: creating a buffer,
  930. copying the contents of the file into the buffer, and then displaying
  931. the buffer for you to edit.  If you alter the text, you can "save" the
  932. new text in the file by typing `C-x C-s' (`save-buffer').  This makes
  933. the changes permanent by copying the altered buffer contents back into
  934. the file `/usr/rms/foo.c'.  Until you save, the changes exist only
  935. inside Emacs, and the file `foo.c' is unaltered.
  936.  
  937.    To create a file, just visit the file with `C-x C-f' as if it
  938. already existed.  This creates an empty buffer in which you can insert
  939. the text you want to put in the file.  The file is actually created when
  940. you save this buffer with `C-x C-s'.
  941.  
  942.    Of course, there is a lot more to learn about using files.  *Note
  943. Files::.
  944.  
  945. 
  946. File: emacs,  Node: Basic Help,  Next: Blank Lines,  Prev: Basic Files,  Up: Basic
  947.  
  948. Help
  949. ====
  950.  
  951.    If you forget what a key does, you can find out with the Help
  952. character, which is `C-h'.  Type `C-h k' followed by the key you want
  953. to know about; for example, `C-h k C-n' tells you all about what `C-n'
  954. does.  `C-h' is a prefix key; `C-h k' is just one of its subcommands
  955. (the command `describe-key').  The other subcommands of `C-h' provide
  956. different kinds of help.  Type `C-h' twice to get a description of all
  957. the help facilities.  *Note Help::.
  958.  
  959. 
  960. File: emacs,  Node: Blank Lines,  Next: Continuation Lines,  Prev: Basic Help,  Up: Basic
  961.  
  962. Blank Lines
  963. ===========
  964.  
  965.    Here are special commands and techniques for putting in and taking
  966. out blank lines.
  967.  
  968. `C-o'
  969.      Insert one or more blank lines after the cursor (`open-line').
  970.  
  971. `C-x C-o'
  972.      Delete all but one of many consecutive blank lines
  973.      (`delete-blank-lines').
  974.  
  975.    When you want to insert a new line of text before an existing line,
  976. you can do it by typing the new line of text, followed by RET.
  977. However, it may be easier to see what you are doing if you first make a
  978. blank line and then insert the desired text into it.  This is easy to do
  979. using the key `C-o' (`open-line'), which inserts a newline after point
  980. but leaves point in front of the newline.  After `C-o', type the text
  981. for the new line.  `C-o F O O' has the same effect as `F O O RET',
  982. except for the final location of point.
  983.  
  984.    You can make several blank lines by typing `C-o' several times, or
  985. by giving it a numeric argument to tell it how many blank lines to make.
  986. *Note Arguments::, for how.  If you have a fill prefix, then `C-o'
  987. command inserts the fill prefix on the new line, when you use it at the
  988. beginning of a line.  *Note Fill Prefix::.
  989.  
  990.    The easy way to get rid of extra blank lines is with the command
  991. `C-x C-o' (`delete-blank-lines').  `C-x C-o' in a run of several blank
  992. lines deletes all but one of them.  `C-x C-o' on a solitary blank line
  993. deletes that blank line.  When point is on a nonblank line, `C-x C-o'
  994. deletes any blank lines following that nonblank line.
  995.  
  996. 
  997. File: emacs,  Node: Continuation Lines,  Next: Position Info,  Prev: Blank Lines,  Up: Basic
  998.  
  999. Continuation Lines
  1000. ==================
  1001.  
  1002.    If you add too many characters to one line without breaking it with
  1003. RET, the line will grow to occupy two (or more) lines on the screen,
  1004. with a `\' at the extreme right margin of all but the last of them.
  1005. The `\' says that the following screen line is not really a distinct
  1006. line in the text, but just the "continuation" of a line too long to fit
  1007. the screen.  Continuation is also called "line wrapping".
  1008.  
  1009.    Sometimes it is nice to have Emacs insert newlines automatically when
  1010. a line gets too long.  Continuation on the screen does not do that.  Use
  1011. Auto Fill mode (*note Filling::.) if that's what you want.
  1012.  
  1013.    As an alternative to continuation, Emacs can display long lines by
  1014. "truncation".  This means that all the characters that do not fit in
  1015. the width of the screen or window do not appear at all.  They remain in
  1016. the buffer, temporarily invisible.  `$' is used in the last column
  1017. instead of `\' to inform you that truncation is in effect.
  1018.  
  1019.    Truncation instead of continuation happens whenever horizontal
  1020. scrolling is in use, and optionally in all side-by-side windows (*note
  1021. Windows::.).  You can enable truncation for a particular buffer by
  1022. setting the variable `truncate-lines' to non-`nil' in that buffer.
  1023. (*Note Variables::.)  Altering the value of `truncate-lines' makes it
  1024. local to the current buffer; until that time, the default value is in
  1025. effect.  The default is initially `nil'.  *Note Locals::.
  1026.  
  1027.    *Note Display Vars::, for additional variables that affect how text
  1028. is displayed.
  1029.  
  1030.